#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/2/25 21:50
# @Author  : jize.liu
# @File    : Maya_BatchOutput.py
# @声明     : 版权由 刘继泽 所有,如有疑问，需要帮助请联系刘继泽
import maya.cmds as cmds
import maya.mel as mel
class Check_isRefLoaded():
	def Check_isRefLoaded(self):

		refFile_Node = []
		refNode = cmds.ls (type="reference")
		refFile = cmds.file (q=True, r=True)
		refFile = [item for item in refFile if item]

		for i in range (len (refFile)) :
			node = cmds.referenceQuery (refFile[i], referenceNode=True)
			refFile_Node.append (node)
			childRefNodes = cmds.referenceQuery (refFile[i], child=True, referenceNode=True)
			refFile_Node.append (childRefNodes)
		result_list = list (set (refNode) - set (refFile_Node)) + list (set (refFile_Node) - set (refNode))
		errNode = [item for item in result_list if item]
		if len (errNode) > 0 :
			for i in errNode :
				cmds.lockNode (i, l=False)
				cmds.delete (i)

		log = ''
		references = cmds.file(q=True, r=True)
		for Ref in references:
			print(Ref)
			filepath = cmds.referenceQuery(Ref,referenceNode=True)
			if cmds.referenceQuery(Ref, isLoaded=True):
				log += filepath + "-YES,"
			else:
				
				log += filepath + "-NO,"
		return(log)